package com.taikang.dao.base;

import com.taikang.util.AssUtils;
import org.apache.log4j.Logger;
import org.nutz.dao.sql.Criteria;

/**
 * Created by zmy on 16/4/4.
 */
public class CustomizeCnd {

    private static Logger logger = Logger.getLogger(CustomizeCnd.class);

    public static Criteria and(Criteria cri, String name, String op, Object value) {
        if (null != value && !value.toString().contains("null"))
            cri.where().and(name, op, value);
        return cri;
    }

    public static Criteria in(Criteria cri, String name, Integer[] value) {

        try {
            if (null != value) {
                int[] values = new int[value.length];
                for (int count = 0 ; count < value.length ; count ++) {
                    values[count] = value[count];
                }
                if (values.length > 0)
                    cri.where().andInIntArray(name, values);
            }
        } catch (Exception e) {
            logger.error(AssUtils.parse(e));
        }
        return cri;
    }

    public static Criteria andLike(Criteria cri, String name, String value) {
        if(null != value) {
            cri.where().andLike(name, value);
        }
        return cri;
    }
}
